var fs = require('fs');
module.exports = function(app){
app.get('/adminList', function(req, res) {
	var User = AV.Object.extend("User");
	var query = new AV.Query(User);
	query.equalTo("usertype", "-1");
	query.find({
		success: function(results) {
			res.render('admin_list', { Users: results });
		},
		error: function(error) {
			res.render('error', { message: error.message });
			console.log('signin false: %j', error.code +" : "+ error.message);	
		}
	});			
});

app.post('/createAdmin', function(req, res) {
	var user = new AV.User();
	user.set("username", req.param('username'));
	user.set("password", req.param('password'));
        user.set("usertype", "-1");
        console.log(req.param('username'));	
        console.log(req.param('password'));	
	user.signUp(null, {
		success: function(user) {
			res.redirect('/adminList');
		},
		error: function(user, error) {
			res.render('error', { message: error.message });
			console.log('signin false: %j', error.code +" : "+ error.message);	
		}
	});
});

app.get('/deleteAdmin', function(req, res) {
	var user = AV.Object.createWithoutData("User", req.param('userId'));
	user.destroy({
		success: function(user) {
			res.redirect('/adminList');
		},
		error: function(user, error) {
			res.render('error', { message: error.message });
			console.log('signin false: %j', error.code +" : "+ error.message);				
		}
	});
});
}
